package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ElderBedInfo;
import com.example.admin.service.ElderBedService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ElderBedController {

    @Autowired
    private ElderBedService elderBedService;

    @GetMapping("/selectElderBedInfoPage")
    public Result<PageInfo> selectElderBedInfoPage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<ElderBedInfo> elderBedInfos=elderBedService.selectElderBedInfoPage();
        PageInfo pageInfo=new PageInfo(elderBedInfos);
        return Result.success(pageInfo);
    }

    @DeleteMapping("/deleteElderBedById/{id}")
    public Result deleteElderBedById(@PathVariable Integer id) {
      Result result=  elderBedService.deleteElderBedById(id);
      return result;
    }

    @PostMapping("/addElderBeb")
    public Result addElderBeb(@RequestBody ElderBedInfo elderBedInfo) {
       Result result= elderBedService.addElderBeb(elderBedInfo);
       return result;
    }

    @PutMapping("/editeElderBed")
    public Result editeElderBed(@RequestBody ElderBedInfo elderBedInfo) {
        Result result=elderBedService.editeElderBed(elderBedInfo);
        return result;
    }

    @GetMapping("/selectElderBedById")
    public Result<PageInfo> selectElderBedById(@RequestParam Integer elderId) {

        PageHelper.startPage(1,10);
       List<ElderBedInfo> elderBedInfoList= elderBedService.selectElderBedById(elderId);
       return Result.success(new PageInfo(elderBedInfoList));
    }

}


